﻿using System.Windows;
using MvvmFx.Samples.HowTos.CommandHandlers.ViewModels;
using MvvmFx.Samples.HowTos.PropertyHandlers.ViewModels;
using MvvmFx.Samples.HowTos.Validation.ViewModel;
using MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels;

namespace MvvmFx.Samples.HowTos.DataTemplateSelector
{
    /// <summary>
    /// The HowTosDataTemplateSelector class.
    /// </summary>
    public class HowTosDataTemplateSelector : Common.DataTemplateSelector.DataTemplateSelectorBase
    {
        /// <summary>
        /// Select the data template applicable to the specified item.
        /// </summary>
        /// <param name="item">The item to determine the associated data template.</param>
        /// <param name="container">The container which consists of the data templates to select from.</param>
        /// <returns>The data template associated to the specified item.</returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement frameworkElement = (FrameworkElement)container;
            if(frameworkElement != null )
            {
                if (item is DeliveryViewModel)
                {
                    return frameworkElement.Resources["ValidationDataTemplate"] as DataTemplate;
                }
                
                if (item is PropertyHandlersViewModel)
                {
                    return frameworkElement.Resources["PropertyHandlersDataTemplate"] as DataTemplate;
                }

                if (item is ViewModelHelperViewModel)
                {
                    return frameworkElement.Resources["ViewModelHelperDataTemplate"] as DataTemplate;
                }

                if (item is CommandHandlersSampleViewModel)
                {
                    return frameworkElement.Resources["CommandHandlersSampleDataTemplate"] as DataTemplate;
                }
            }
            
            return null;
        }
    }
}
